using System;
using System.Collections.Generic;
using Holoville.HOTween;
using UnityEngine;

[RequireComponent(typeof(tk2dUIItem))]
public class tk2dUIChildColorUpDown : MonoBehaviour
{
	private void Start()
	{
		tk2dBaseSprite[] componentsInChildren = base.GetComponentsInChildren<tk2dBaseSprite>(true);
		tk2dTextMesh[] componentsInChildren2 = base.GetComponentsInChildren<tk2dTextMesh>(true);
		TextMesh[] componentsInChildren3 = base.GetComponentsInChildren<TextMesh>(true);
		foreach (tk2dBaseSprite tk2dBaseSprite in componentsInChildren)
		{
			tk2dUIChildColorUpDown.Tk2dColorSprite tk2dColorSprite = new tk2dUIChildColorUpDown.Tk2dColorSprite();
			tk2dColorSprite.tk2dSprite = tk2dBaseSprite;
			tk2dColorSprite.upColor = tk2dBaseSprite.color;
			this.tk2dSprites.Add(tk2dColorSprite);
		}
		foreach (tk2dTextMesh tk2dTextMesh in componentsInChildren2)
		{
			tk2dUIChildColorUpDown.Tk2dColorTextMesh tk2dColorTextMesh = new tk2dUIChildColorUpDown.Tk2dColorTextMesh();
			tk2dColorTextMesh.tk2dTextMesh = tk2dTextMesh;
			tk2dColorTextMesh.upColor = tk2dTextMesh.color;
			this.tk2dTextMeshs.Add(tk2dColorTextMesh);
		}
		foreach (TextMesh textMesh in componentsInChildren3)
		{
			tk2dUIChildColorUpDown.ColorTextMesh colorTextMesh = new tk2dUIChildColorUpDown.ColorTextMesh();
			colorTextMesh.textMesh = textMesh;
			colorTextMesh.upColor = textMesh.color;
			this.textMeshs.Add(colorTextMesh);
		}
	}

	private void OnEnable()
	{
		tk2dUIItem component = base.GetComponent<tk2dUIItem>();
		if (component != null)
		{
			component.OnDownUIItem += this.OnDown;
			component.OnUpUIItem += this.OnUp;
		}
	}

	private void OnDisable()
	{
		tk2dUIItem component = base.GetComponent<tk2dUIItem>();
		if (component != null)
		{
			component.OnDownUIItem -= this.OnDown;
			component.OnUpUIItem -= this.OnUp;
		}
	}

	private void OnDown(tk2dUIItem item)
	{
		this.SetColor(true);
	}

	private void OnUp(tk2dUIItem item)
	{
		this.SetColor(false);
	}

	private void SetColor(bool isDown)
	{
		foreach (tk2dUIChildColorUpDown.Tk2dColorSprite tk2dColorSprite in this.tk2dSprites)
		{
			HOTween.Kill(tk2dColorSprite.tk2dSprite);
			HOTween.To(tk2dColorSprite.tk2dSprite, 0.2f, "color", (!isDown) ? tk2dColorSprite.upColor : this.downColor);
		}
		foreach (tk2dUIChildColorUpDown.Tk2dColorTextMesh tk2dColorTextMesh in this.tk2dTextMeshs)
		{
			HOTween.Kill(tk2dColorTextMesh.tk2dTextMesh);
			HOTween.To(tk2dColorTextMesh.tk2dTextMesh, 0.2f, "color", (!isDown) ? tk2dColorTextMesh.upColor : this.downColor);
		}
		foreach (tk2dUIChildColorUpDown.ColorTextMesh colorTextMesh in this.textMeshs)
		{
			HOTween.Kill(colorTextMesh.textMesh.GetComponent<Renderer>().material);
			HOTween.To(colorTextMesh.textMesh.GetComponent<Renderer>().material, 0.2f, "color", (!isDown) ? colorTextMesh.upColor : this.downColor);
		}
	}

	public Color downColor = Color.white;

	private List<tk2dUIChildColorUpDown.Tk2dColorSprite> tk2dSprites = new List<tk2dUIChildColorUpDown.Tk2dColorSprite>();

	private List<tk2dUIChildColorUpDown.Tk2dColorTextMesh> tk2dTextMeshs = new List<tk2dUIChildColorUpDown.Tk2dColorTextMesh>();

	private List<tk2dUIChildColorUpDown.ColorTextMesh> textMeshs = new List<tk2dUIChildColorUpDown.ColorTextMesh>();

	private class Tk2dColorSprite
	{
		public tk2dBaseSprite tk2dSprite;

		public Color upColor = Color.white;
	}

	private class Tk2dColorTextMesh
	{
		public tk2dTextMesh tk2dTextMesh;

		public Color upColor = Color.white;
	}

	private class ColorTextMesh
	{
		public TextMesh textMesh;

		public Color upColor = Color.white;
	}
}
